package com.example.sxproject.controller;
import com.example.sxproject.mapper.CompanyMapper;
import com.example.sxproject.pojo.*;
import com.example.sxproject.service.*;
import com.google.gson.Gson; //JSON转String的依赖


import com.google.gson.Gson;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.bind.annotation.CrossOrigin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.springframework.util.ObjectUtils.isEmpty;

@RestController
public class ReManangerController {

    @Autowired
    private UserService userService;
    @Autowired
    private PaymentService paymentService;
    @Autowired
    private FinancialService financialService;
    @Autowired
    private CardService cardService;
    @Autowired
    private CompanyService companyService;
    @Autowired
    private LoanService loanService;

    @GetMapping("/userMessage")
    public Map<String, Object> selectUser(User user, String searchParams) {

        String w, m;
        System.out.println("searchParams:" + searchParams);     //searchParams为搜索时表单提交到后台的JSON变量

        if (searchParams != null) {
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (!t.getCardId().isEmpty()) { //JSON不传参时默认时empty，无法被识别
                w = t.getCardId();
            } else {
                w = null;
            }

            System.out.println("t.getPhone:" + t.getPhone());

            if (!t.getPhone().isEmpty()) {
                m = t.getPhone();
                System.out.println("aaaa");
            } else {
                m = null;
                System.out.println("bbbbb");
            }
            user.setPhone(m);   //将转化后的数据传给user用于判断
            user.setCardId(w);
        }


        System.out.println("user:" + user);

        List<Map<String, String>> data = new ArrayList<>();
        List<User> users;
        System.out.println("user空吗："+user==null);
        if (user == null) {
            users = userService.selectAll();   //当没有检索条件时查全部
        } else {
            users = userService.selectUser(user);  //有检索条件时按条件查找
        }

        if (users == null) {

            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (User a : users) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId()));
                map.put("realName", a.getRealName());
                map.put("birthday", a.getBirthday());
                map.put("sex", String.valueOf(a.getSex()));
                map.put("cardId", a.getCardId());
                map.put("address", a.getAddress());
                map.put("phone", a.getPhone());
                map.put("mail", a.getMail());
                map.put("password", "******");
                map.put("creditScore", String.valueOf(a.getCreditScore()));
                map.put("userType", String.valueOf(a.getUserType()));
                map.put("photo", a.getPhoto());
                map.put("userStatus", String.valueOf(a.getUserStatus()));
                map.put("houseNumber", a.getHouseNumber());
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            System.out.println(result);
            return result;
        }
    }

    public class SearchParams {  //JSON转化后的pojo类
        private String cardId;
        private String phone;
        public String getCardId() {
            return cardId;
        }
        public String getPhone() {
            return phone;
        }


        private String id;
        private String idNumber; //流水号
        private String transType; //转入转出
        private String payType; //支付类型
        private String recardId; //接收方账户
        private String userId; //所属用户
        private String payDate;
        private String money;
        private String paymentStatus;

        public String getId() {
            return id;
        }
        public String getIdNumber() {
            return idNumber;
        }
        public String getTransType() {
            return transType;
        }
        public String getPayType() {
            return payType;
        }
        public String getRecardId() {
            return recardId;
        }
        public String getUserId() {
            return userId;
        }
        public String getPayDate() {
            return payDate;
        }
       public String getMoney(){
            return money;
       }
       public String getPaymentStatus(){
            return  paymentStatus;
       }



        private String productName; // 产品名称
        private String costStatus; // 销售状态

        public String getProductName() {
            return productName;
        }

        public String getCostStatus() {
            return costStatus;
        }

        public  String getLowTime() {
            return lowTime;
        }

        public String getHighTime() {
            return highTime;
        }

        public String getRiskType() {
            return riskType;
        }

        public String getOcType() {
            return ocType;
        }

        private String lowTime;   // 时间下限
        private String highTime;   // 时间上限
        private String riskType;   // 风险等级
        private String ocType;     //开封闭类型


        private String belongUser; //所属用户
        private String belongProduct; //所属产品
        private String balance; //产品余额
        private String productStatus; // 产品状态

        public String getBelongUser() {
            return belongUser;
        }

        public String getBelongProduct() {
            return belongProduct;
        }

        public String getBalance() {
            return balance;
        }

        public String getProductStatus() {
            return productStatus;
        }


        public String getCardType() {
            return cardType;
        }

        private String cardType;

        private String companyName; //公司名称
        private String city; //所在城市
        private String companyType; //公司类型

        public String getCompanyName() {
            return companyName;
        }

        public String getCity() {
            return city;
        }

        public String getCompanyType() {
            return companyType;
        }

        public String getCompanyCount() {
            return companyCount;
        }

        public String getCompanyStatus() {
            return companyStatus;
        }

        private String companyCount; //公司账户
        private String companyStatus; //公司状态



        private String beginDate; //贷款起始日期
        private String timeContinue; //贷款期限(月数)
        private String incomeType; //贷款类型

        public String getBeginDate() {
            return beginDate;
        }

        public String getTimeContinue() {
            return timeContinue;
        }

        public String getIncomeType() {
            return incomeType;
        }

        public String getBeginMoney() {
            return beginMoney;
        }

        public String getLoanRate() {
            return loanRate;
        }

        public String getInterest() {
            return interest;
        }

        public String getLoanStatus() {
            return loanStatus;
        }

        private String beginMoney; //贷款金额
        private String loanRate; //利率
        private String interest; //利息
        private String loanStatus; //贷款产品状态



        private String productId; //所属贷款

        public String getProductId() {
            return productId;
        }

        public String getEndDate() {
            return endDate;
        }

        private String endDate; //贷款到期时间

    }


    //管理员账户查询
    @GetMapping("/paymentMessage")
    public Map<String, Object> selectPayments(SearchStr  searchStr, String searchParams) {
       /* System.out.println("searchStr1:"+searchStr);
        System.out.println("searchParams:"+searchParams);*/
        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);
            if(t.getId() != null &&!t.getId().isEmpty()&&!"null".equals((t.getId()))){
                searchStr.setId(Integer.valueOf(t.getId()));
            } else{
                searchStr.setId(null);
            }

            if (t.getIdNumber() != null && !t.getIdNumber().isEmpty() && !"null".equals(t.getIdNumber())) {
                searchStr.setIdNumber(t.getIdNumber());
            } else {
                searchStr.setIdNumber(null);
            }

            if (t.getTransType() != null && !t.getTransType().isEmpty() && !"null".equals(t.getTransType())) {
                searchStr.setTransType(Integer.valueOf(t.getTransType()));
            } else {
                searchStr.setTransType(null);
            }

            if (t.getPayType() != null && !t.getPayType().isEmpty() && !"null".equals(t.getPayType())) {
                searchStr.setPayType(Integer.valueOf(t.getPayType()));
            } else {
                searchStr.setPayType(null);
            }

            if (t.getRecardId() != null && !t.getRecardId().isEmpty() && !"null".equals(t.getRecardId())) {
                searchStr.setRecardId(t.getRecardId());
            } else {
                searchStr.setRecardId(null);
            }

            if (t.getUserId() != null && !t.getUserId().isEmpty() && !"null".equals(t.getUserId())) {
                searchStr.setUserId(Integer.valueOf(t.getUserId()));
            } else {
                searchStr.setUserId(null);
            }

            if (t.getPayDate() != null && !t.getPayDate().isEmpty() && !"null".equals(t.getPayDate())) {
                searchStr.setPayDate(t.getPayDate());
            } else {
                searchStr.setPayDate(null);
            }

            if (t.getMoney() != null && !t.getMoney().isEmpty() && !"null".equals(t.getMoney())) {
                searchStr.setMoney(t.getMoney());
            } else {
                searchStr.setMoney(null);
            }

            if (t.getPaymentStatus() != null && !t.getPaymentStatus().isEmpty() && !"null".equals(t.getPaymentStatus())) {
                searchStr.setPaymentStatus(Integer.valueOf(t.getPaymentStatus()));
            } else {
                searchStr.setPaymentStatus(null);
            }

        }

        System.out.println("searchStr2:"+searchStr);

        List<Map<String, String>> data = new ArrayList<>();
        List<Payment> payments;
        if (searchParams == null) {
            payments = paymentService.selectAll();   //当没有检索条件时查全部
        }
        else {
           /* System.out.println("进来了");*/
            payments = paymentService.selectBySearchStr(searchStr);  //有检索条件时按条件查找
           /* System.out.println("payments:"+payments);*/
        }

        if (payments == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (Payment a : payments) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 新增字段
                map.put("idNumber", a.getIdNumber()); // 新增字段
                map.put("cardId", a.getCardId()); // 新增字段
                map.put("transType", String.valueOf(a.getTransType())); // 新增字段
                map.put("payType", String.valueOf(a.getPayType())); // 新增字段
                map.put("recardId", a.getRecardId()); // 新增字段
                map.put("userId", String.valueOf(a.getUserId())); // 新增字段
                map.put("payDate", a.getPayDate()); // 注意Java命名规范，已改为highTime
                map.put("money", String.valueOf(a.getMoney())); // 新增字段，假设lowMoney是Integer类型
                map.put("paymentStatus",String.valueOf(a.getPaymentStatus()));
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    //管理员交易记录更新
    @PostMapping("/paymentMessageUpdate")
    public Result paymentMessageUpdate(Payment payment) {
        System.out.println("Payment"+payment);
        paymentService.paymentMessageUpdate(payment);
        return Result.success();
    }

    //交易信息假删除
    @PostMapping("/paymentMessageDel")
    public Result aymentMessageDel(Integer id){
        paymentService.PaymentDl(id);
        return Result.success();
    }




    //用户信息更新
    @PostMapping("/userMessageUpdate")
    public Result userMessageUpdate(User user) {
        System.out.println("User"+user);
        userService.userMessageUpdate(user);
        return Result.success();
    }


    //用户信息假删除
    @PostMapping("/userMessageDel")
    public Result userMessageDel(Integer id){
        System.out.println("id"+id);
        userService.deleteUser(id);
        return Result.success();
    }


    //管理员查看理财产品
    @GetMapping("/financeMessage")
    public Map<String, Object> selectfinance(FPSearch fpSearch, String searchParams) {

        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (t.getProductName() != null && !t.getProductName().isEmpty() && !"null".equals(t.getProductName())) {
                fpSearch.setProductName(t.getProductName());
            } else {
                fpSearch.setProductName(null);
            }

            if (t.getCostStatus() != null&& !t.getCostStatus().isEmpty() && !"null".equals(t.getCostStatus())) {
                fpSearch.setCostStatus(Integer.valueOf(t.getCostStatus()));
            } else {
                fpSearch.setCostStatus(null);
            }

            if (t.getOcType() != null&& !t.getOcType().isEmpty() && !"null".equals(t.getOcType())) {
                fpSearch.setOcType(Integer.valueOf(t.getOcType()));
            } else {
                fpSearch.setOcType(null);
            }

            if (t.getRiskType() != null&& !t.getRiskType().isEmpty() && !"null".equals(t.getRiskType())) {
                fpSearch.setRiskType(Integer.valueOf(t.getRiskType()));
            } else {
                fpSearch.setRiskType(null);
            }

            if(t.getHighTime()!=null&& !t.getHighTime().isEmpty() && !"null".equals(t.getHighTime())){
                fpSearch.setHighTime(Integer.valueOf(t.getHighTime()));
            }else {
                fpSearch.setHighTime(null);
            }

            if(t.getLowTime()!=null&& !t.getLowTime().isEmpty() && !"null".equals(t.getLowTime())){
                fpSearch.setLowTime(Integer.valueOf(t.getLowTime()));
            }else {
                fpSearch.setLowTime(null);
            }
        }

        List<Map<String, String>> data = new ArrayList<>();
        List<FinancialProduct> financialProducts;
        financialProducts = financialService.SelectFPSearch(fpSearch);  //有检索条件时按条件查找
        if (financialProducts == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (FinancialProduct a : financialProducts) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 新增字段
                map.put("productName", a.getProductName()); // 产品名称
                map.put("buyBeginDate", a.getBuyBeginDate()); // 购买起始日期
                map.put("buyEndDate", a.getBuyEndDate()); // 购买终止日期
                map.put("beginDate", a.getBeginDate()); // 产品起始日期
                map.put("endDate", a.getEndDate()); // 产品终止日期
                map.put("timeContinue", String.valueOf(a.getTimeContinue())); // 期限
                map.put("incomeType", String.valueOf(a.getIncomeType())); // 收益类型
                map.put("beginMoney", String.valueOf(a.getBeginMoney())); // 起购金额
                map.put("costStatus", String.valueOf(a.getCostStatus())); // 销售状态
                map.put("currencyType", String.valueOf(a.getCurrencyType())); // 币种
                map.put("ocType", String.valueOf(a.getOcType())); // 开封闭类型
                map.put("riskType", String.valueOf(a.getRiskType())); // 风险等级
                map.put("institution", a.getInstitution()); // 发行机构
                map.put("lowRate", String.valueOf(a.getLowRate())); // 最低年利率
                map.put("highRate", String.valueOf(a.getHighRate())); // 最高年利率
                map.put("productStatus",String.valueOf(a.getProductStatus())); // 产品状态
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
            }
    }


    //添加理财产品








    //查询用户所拥有的理财产品
    @PostMapping("/financialUser")
    public Map<String, Object> selectfinance(FinancialUser financialUser,String searchParams) {

        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (t.getBelongUser() != null && !t.getBelongUser().isEmpty() && !"null".equals(t.getBelongUser())) {
                financialUser.setBelongUser(Integer.valueOf(t.getBelongUser()));
            } else {
                financialUser.setBelongUser(null);
            }

            if (t.getBelongProduct() != null&& !t.getBelongProduct().isEmpty() && !"null".equals(t.getBelongProduct())) {
                financialUser.setBelongProduct(Integer.valueOf(t.getBelongProduct()));
            } else {
                financialUser.setBelongProduct(null);
            }

        }

        List<Map<String, String>> data = new ArrayList<>();
        List<FinancialUser> financialUsers;
        financialUsers = financialService.selectFu(financialUser);  //有检索条件时按条件查找
        if (financialUsers == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (FinancialUser a : financialUsers) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 新增字段
                map.put("belongUser", String.valueOf(a.getBelongUser())); // 产品名称
                map.put("belongProduct", String.valueOf(a.getBelongProduct())); // 购买起始日期
                map.put("balance",String.valueOf(a.getBalance()));
                map.put("productStatus", String.valueOf(a.getProductStatus())); // 购买终止日期

                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }



    //银行卡信息
    @GetMapping("/cardMessage")
    public Map<String, Object> selectCard(Card card, String searchParams) {
        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (t.getCardType() != null && !t.getCardType().isEmpty() && !"null".equals(t.getCardType())) {
                card.setCardType(Integer.valueOf(t.getCardType()));
            } else {
                card.setCardType(null);
            }

            if (t.getUserId() != null&& !t.getUserId().isEmpty() && !"null".equals(t.getUserId())) {
                card.setUserId(Integer.valueOf(t.getUserId()));
            } else {
                card.setUserId(null);
            }

        }

        List<Map<String, String>> data = new ArrayList<>();
        List<Card> cards;
        cards = cardService.selectByTI(card);  //有检索条件时按条件查找
        if (cards == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (Card a : cards) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("idNumber", a.getIdNumber()); // 卡号唯一
                map.put("cardType", String.valueOf(a.getCardType())); // 银行卡类型
                map.put("password", a.getPassword()); // 密码，注意：密码通常不应该这样存储或传输，应该使用安全的加密方法
                map.put("balance", String.valueOf(a.getBalance())); // 余额
                map.put("statusId", String.valueOf(a.getStatusId())); // 状态编号
                map.put("userId", String.valueOf(a.getUserId())); // 所属用户
                map.put("beginDate", a.getBeginDate()); // 开户日期，假设是String类型
                map.put("repaid", String.valueOf(a.getRepaid())); // 信用卡待还款
                map.put("total", String.valueOf(a.getTotal())); // 信用卡额度
                map.put("rate", String.valueOf(a.getRate())); // 日利率，这里使用double来存储货币相关的数值可能会导致精度问题，通常建议使用BigDecimal
                map.put("repayDate", a.getRepayDate()); // 还款日期
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }


    //信用卡申请信息查看
    @GetMapping("/cardReviewMessage")
    public Map<String, Object> selectCard() {
        List<Map<String, String>> data = new ArrayList<>();
        List<Card> cards;
        cards = cardService.findByStatusId();  //有检索条件时按条件查找
        if (cards == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (Card a : cards) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("idNumber", a.getIdNumber()); // 卡号唯一
                map.put("cardType", String.valueOf(a.getCardType())); // 银行卡类型
                map.put("password", a.getPassword()); // 密码，注意：密码通常不应该这样存储或传输，应该使用安全的加密方法
                map.put("balance", String.valueOf(a.getBalance())); // 余额
                map.put("statusId", String.valueOf(a.getStatusId())); // 状态编号
                map.put("userId", String.valueOf(a.getUserId())); // 所属用户
                map.put("beginDate", a.getBeginDate()); // 开户日期，假设是String类型
                map.put("repaid", String.valueOf(a.getRepaid())); // 信用卡待还款
                map.put("total", String.valueOf(a.getTotal())); // 信用卡额度
                map.put("rate", String.valueOf(a.getRate())); // 日利率，这里使用double来存储货币相关的数值可能会导致精度问题，通常建议使用BigDecimal
                map.put("repayDate", a.getRepayDate()); // 还款日期
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    //信用卡开户
    @PostMapping("/cardReviewMessageUpdate")
    public Result cardReviewUpdate(Card card) {
        cardService.kaihu(card);
        return Result.success();
    }

    //信用卡开户申请驳回
    @PostMapping("/cardNoReview")
    public Result cardNoReview(Integer id) {
        cardService.bohui(id);
        return Result.success();
    }

    //公司信息查询
    @GetMapping("companyMessage")
    public Map<String, Object> companyMessage(Company company,String searchParams) {
        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (t.getCity() != null && !t.getCity().isEmpty() && !"null".equals(t.getCity())) {
                company.setCity(t.getCity());
            } else {
                company.setCity(null);
            }

            if (t.getCompanyType() != null&& !t.getCompanyType().isEmpty() && !"null".equals(t.getCompanyType())) {
                company.setCompanyType(Integer.valueOf(t.getCompanyType()));
            } else {
                company.setCompanyType(null);
            }
        }

        List<Map<String, String>> data = new ArrayList<>();
        List<Company> companies;
        companies = companyService.selectCompanyByCT(company);  //有检索条件时按条件查找
        if (companies == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (Company a : companies) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("companyName", a.getCompanyName()); // 公司名称
                map.put("city", a.getCity()); // 所在城市
                map.put("companyType", String.valueOf(a.getCompanyType())); // 公司类型
                map.put("companyCount", a.getCompanyCount()); // 公司账户（假设这里已经是String类型）
                map.put("companyStatus", String.valueOf(a.getCompanyStatus())); // 公司状态
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    //公司信息编辑
    @PostMapping("/companyMessageUpdate")
    public Result companyMessageUpdate(Company company) {
        companyService.updateCompany(company);
        return Result.success();
    }

    //公司注销
    @PostMapping("/companyMessageDelete")
    public Result companyMessageDelete(Integer id) {
        companyService.companyDel(id);
        return Result.success();
    }









    //贷款产品信息
    @GetMapping("loanProductMessage")
    public Map<String, Object> loanProductMessage(LoanProduct loanProduct,String searchParams) {
        if(searchParams!=null){
            Gson gson = new Gson();               //转pojo操作
            ReManangerController.SearchParams t = gson.fromJson(searchParams, ReManangerController.SearchParams.class);

            if (t.getIncomeType() != null && !t.getIncomeType().isEmpty() && !"null".equals(t.getIncomeType())) {
                loanProduct.setIncomeType(Integer.valueOf(t.getIncomeType()));
            } else {
                loanProduct.setIncomeType(null);
            }

            if (t.getProductName() != null&& !t.getProductName().isEmpty() && !"null".equals(t.getProductName())) {
                loanProduct.setProductName(t.getProductName());
            } else {
                loanProduct.setProductName(null);
            }
        }

        List<Map<String, String>> data = new ArrayList<>();
        List<LoanProduct> loanProducts;
        loanProducts = loanService.selectNT(loanProduct);  //有检索条件时按条件查找
        if (loanProducts == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (LoanProduct a : loanProducts) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("productName", a.getProductName()); // 公司名称
                map.put("beginDate", a.getBeginDate()); // 所在城市
                map.put("timeContinue", String.valueOf(a.getTimeContinue())); // 公司类型
                map.put("incomeType", String.valueOf(a.getIncomeType())); // 公司账户（假设这里已经是String类型）
                map.put("beginMoney",String.valueOf(a.getBeginMoney())); // 公司状态
                map.put("loanRate", String.valueOf(a.getLoanRate())); // 公司类型
                map.put("interest", String.valueOf(a.getInterest())); // 公司账户（假设这里已经是String类型）
                map.put("loanStatus",String.valueOf(a.getLoanStatus()));
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    //增加贷款产品






    //更新贷款信息
    @PostMapping("loanProductMessageUpdate")
    public Result loanProductMessageUpdate(LoanProduct loanProduct) {
        loanService.update(loanProduct);
        return Result.success();
    }

    @GetMapping("loanUserMessage")
    public Map<String, Object> loanUserMessage() {

        List<Map<String, String>> data = new ArrayList<>();
        List<LoanUser> loanUsers;
        loanUsers = loanService.selectAllUser();  //有检索条件时按条件查找
        if (loanUsers == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (LoanUser a : loanUsers) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("userId", String.valueOf(a.getUserId())); // 公司名称
                map.put("productId",String.valueOf(a.getProductId())); // 所在城市
                map.put("balance", String.valueOf(a.getBalance())); // 公司类型
                map.put("productStatus", String.valueOf(a.getProductStatus())); // 公司账户（假设这里已经是String类型）
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    @GetMapping("loanUserApplyMessage")
    public Map<String, Object> loanUserApplyMessage() {

        List<Map<String, String>> data = new ArrayList<>();
        List<LoanUser> loanUsers;
        loanUsers = loanService.selectApply();  //有检索条件时按条件查找
        if (loanUsers == null) {
            return null;
        } else {     //若users不空（查询条件不空）则把User类型中的数据转给map
            for (LoanUser a : loanUsers) {
                Map<String, String> map = new HashMap<>();
                map.put("id", String.valueOf(a.getId())); // 编号唯一自增，已经是Integer类型，不需要转换为String
                map.put("userId", String.valueOf(a.getUserId())); // 公司名称
                map.put("productId",String.valueOf(a.getProductId())); // 所在城市
                map.put("balance", String.valueOf(a.getBalance())); // 公司类型
                map.put("productStatus", String.valueOf(a.getProductStatus())); // 公司账户（假设这里已经是String类型）
                data.add(map); //data是map列表
            }
            Map<String, Object> result = new HashMap<>(); //封装为前端可识别格式
            result.put("code", 0);
            result.put("msg", "");
            result.put("count", data.size());
            result.put("data", data);


            /*System.out.println(result);*/
            return result;
        }
    }

    @PostMapping("loanApplyPass")
    public Result loanApplyPass(Integer id) {
        loanService.tongguo(id);
        return Result.success();
    }


    @PostMapping("loanApplyReject")
    public Result loanApplyReject(Integer id) {
        loanService.jujue(id);
        return Result.success();
    }


}




